/*
 * Created on Jul 5, 2005
 *
 */
package com.erclab.internal.xpresso.unittests;

import com.erclab.internal.xpresso.conf.Settings;
import com.erclab.internal.xpresso.exceptions.ApplicationException;
import com.erclab.internal.xpresso.exceptions.ClonerException;
import com.erclab.internal.xpresso.exceptions.DirectoryException;
import com.erclab.internal.xpresso.exceptions.FormException;
import com.erclab.internal.xpresso.exceptions.ReportException;
import com.erclab.internal.xpresso.forms.Form;
import com.erclab.internal.xpresso.reports.Report;
import com.erclab.internal.xpresso.security.User;
import com.erclab.internal.xpresso.util.MysqlCloner;
import com.erclab.internal.xpresso.*;

import junit.framework.TestCase;

/**
 * @author Enrique Rodriguez.
 *
 */
public class MysqlClonerTest extends TestCase {

	Application xpresso = null;
	User user = null;

	/**
	 * Constructor for MysqlClonerTest.
	 * @param arg0
	 */
	public MysqlClonerTest(String arg0) {
		super(arg0);
	}
	
	protected void setUp() throws Exception {
		super.setUp();
		try {
			xpresso = new Application();
		} catch(ApplicationException e){
			fail("Create Application failed: " + e.toString());
		}
		user = new User();
		try {
			Settings.getUserDirectory().loadUserBean(user);
		} catch (DirectoryException e) {
			fail();
			e.printStackTrace();
		}
	}
	
	public void testCloneReport(){
		Report r = null;
		try {
			r = ReportFactory.loadReport("Reports");
		} catch (ReportException e) {
			e.printStackTrace();
			fail();
		}
		
		MysqlCloner mc = new MysqlCloner();
		try {
			mc.cloneReport(r, "UNIT TEST CLONE", 1);
		} catch (ClonerException e1) {
			e1.printStackTrace();
			fail();
		}
	}
	
	public void testCloneForm(){
		Form f = null;
		try {
			f = FormFactory.loadForm("Forms");
		} catch (FormException e) {
			e.printStackTrace();
			fail();
		}
		
		MysqlCloner mc = new MysqlCloner();
		try {
			mc.cloneForm(f, "CLONE UNIT TEST", 1);
		} catch (ClonerException e1) {
			e1.printStackTrace();
			fail();
		}
	}

}
